import {
  Column,
  Entity,
  AfterLoad,
  PrimaryColumn,
  BeforeInsert,
  BeforeUpdate,
  PrimaryGeneratedColumn,
} from "typeorm";
import { v4 as uuidv4 } from "uuid";
import moment from "moment";

@Entity({ name: "user" })
export class UsersEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    type: "varchar",
    length: 30,
    nullable: false,
    unique: true,
  })
  username: string;

  @Column({
    type: "varchar",
    name: "password",
    length: 100,
    nullable: false,
    select: false,
    comment: "密码",
  })
  password: string;

  @Column({ type: "varchar", nullable: true })
  created_at: string;

  @Column({ type: "varchar", nullable: true })
  updated_at: string;

  @BeforeInsert()
  createDates() {
    this.created_at = moment().format("YYYY-MM-DD HH:mm:ss");
  }

  @BeforeUpdate()
  updateDates() {
    this.updated_at = moment().format("YYYY-MM-DD HH:mm:ss");
  }
}
